﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObjects.BO_GetObjects;
using System.Web.UI.HtmlControls;

public partial class Pages_BookByID : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetMetaTags("E-Book");
            LoadLeftModule();
            LoadRightModule();
            LoadSidebarModule();
        }
    }

    protected void SetMetaTags(string title)
    {
        MasterPage master = Page.Master;
        HtmlHead headTag = (HtmlHead)master.Page.Header;
        headTag.Title = "Luật Phúc Trung | " + title;
    }

    protected void LoadLeftModule()
    {
        DataTable objDT = null;
        objDT = BO_Module.SelectLocation(4, Convert.ToInt32(Request["cid"]));

        UserControl controls1 = (UserControl)Page.LoadControl("../controls/ucEBookDetail.ascx");
        plHolderLeft.Controls.Add(controls1);

        for (int i = 0; i < objDT.Rows.Count; i++)
        {
            if (objDT.Rows[i]["type_id"].ToString() == "1")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucSlider.ascx");
                Controls_ucSlider control = (Controls_ucSlider)controls;
                control.Module_id = objDT.Rows[i]["MODULE_ID"].ToString();
                plHolderLeft.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "2")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucFeaturedContent.ascx");
                Controls_ucFeaturedContent control = (Controls_ucFeaturedContent)controls;
                control.Module_id = objDT.Rows[i]["MODULE_ID"].ToString();
                plHolderLeft.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "7")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucFeaturedEbook.ascx");
                Controls_ucFeaturedEbook control = (Controls_ucFeaturedEbook)controls;
                control.Module_id = objDT.Rows[i]["MODULE_ID"].ToString();
                plHolderLeft.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "11")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucListNews.ascx");
                Controls_ucListNews control = (Controls_ucListNews)controls;
                control.Category_id = objDT.Rows[i]["MODULE_CONTENT"].ToString();
                control.Page_size = objDT.Rows[i]["PAGE_SIZE"].ToString();
                if (control.Page_size == "")
                {
                    control.Page_size = "10";
                }
                plHolderLeft.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "12")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucListService.ascx");
                Controls_ucListNews control = (Controls_ucListNews)controls;
                control.Module_id = objDT.Rows[i]["MODULE_ID"].ToString();
                plHolderLeft.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "13")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucListEbook.ascx");
                Controls_ucListEbook control = (Controls_ucListEbook)controls;
                control.Module_id = objDT.Rows[i]["MODULE_ID"].ToString();
                plHolderLeft.Controls.Add(controls);
            }
        }
    }

    protected void LoadRightModule()
    {
        DataTable objDT = null;
        objDT = BO_Module.SelectLocation(5, Convert.ToInt32(Request["cid"]));
        for (int i = 0; i < objDT.Rows.Count; i++)
        {
            if (objDT.Rows[i]["type_id"].ToString() == "9")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucFeaturedContentSidebar.ascx");
                Controls_ucFeaturedContentSidebar control = (Controls_ucFeaturedContentSidebar)controls;
                plHolderRight.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "10")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucFeaturedEbookSidebar.ascx");
                Controls_ucFeaturedEbookSidebar control = (Controls_ucFeaturedEbookSidebar)controls;
                plHolderRight.Controls.Add(controls);
            }
        }
    }

    protected void LoadSidebarModule()
    {
        DataTable objDT = null;
        objDT = BO_Module.SelectLocation(3);
        for (int i = 0; i < objDT.Rows.Count; i++)
        {
            if (objDT.Rows[i]["type_id"].ToString() == "3")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucCustomSearch.ascx");
                Controls_ucCustomSearch control = (Controls_ucCustomSearch)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "4")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucRegistService.ascx");
                Controls_ucRegistService control = (Controls_ucRegistService)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "5")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucSupport.ascx");
                Controls_ucSupport control = (Controls_ucSupport)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "6")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucAds.ascx");
                Controls_ucAds control = (Controls_ucAds)controls;
                control.Module_id = objDT.Rows[i]["MODULE_ID"].ToString();
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "7")
            {
                //UserControl controls = (UserControl)Page.LoadControl("../controls/ucRegistService.ascx");
                //Controls_ucRegistService control = (Controls_ucRegistService)controls;
                //pldHolderLeft.Controls.Add(controls);
            }
        }
    }
}